/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.system;

import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.model.DashboardColumn;
import org.primefaces.model.DashboardModel;
import org.primefaces.model.DefaultDashboardColumn;
import org.primefaces.model.DefaultDashboardModel;

/**
 *
 * @author chan
 */
@ManagedBean
@SessionScoped
public class DashboardBean implements Serializable{
    private DashboardModel model;
    private UserDashboard userDashBoard;

    public DashboardBean() {
      userDashBoard = new UserDashboard();
    }
    
    @PostConstruct
    public void init(){
        model = new DefaultDashboardModel();
        DashboardColumn column1 = new DefaultDashboardColumn();
        DashboardColumn column2 = new DefaultDashboardColumn();
        DashboardColumn column3 = new DefaultDashboardColumn();
        
        
        userDashBoard.loadDashboard();
        
        for (int i=0;i<userDashBoard.getListDashboard().size()-1;i++){
            Dashboard dsb = userDashBoard.getListDashboard().get(i);
            switch (dsb.getColumn()){
                case 1 : column1.addWidget(dsb.getId());
                case 2 : column2.addWidget(dsb.getId());
                default : column3.addWidget(dsb.getId());
            }
        }
        
       /* column1.addWidget("finance");
        column1.addWidget("GL");
        
        column2.addWidget("saving");
        column2.addWidget("loan");
        
        column3.addWidget("deposit");
        
        */
        
        model.addColumn(column1);
        model.addColumn(column2);
        model.addColumn(column3);
    }

    public DashboardModel getModel() {
        return model;
    }

    public void setModel(DashboardModel model) {
        this.model = model;
    }

    public UserDashboard getUserDashBoard() {
        return userDashBoard;
    }
    
    
    
}
